//
//  BKLHealth_MCCollectionCell.m
//  BKLMedicalCare
//
//  Created by ma c on 2017/6/19.
//  Copyright © 2017年 q mac. All rights reserved.
//

#import "BKLHealth_MCCollectionCell.h"
#import <Masonry.h>

#pragma mark - collection cell 基类
#pragma mark -
@implementation BKLHealth_MCCollectionCell
- (void)fillData:(id)data{}
+ (CGSize)computeSize:(id)data {
    return CGSizeZero;
}
@end

#pragma mark - 文章分页 collection cell
#pragma mark -

#import "BKLHealth_MCTableCell.h"
@interface BKLHealth_MCCArticlePageCell ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, copy)NSArray *dataSource;
@end

@implementation BKLHealth_MCCArticlePageCell

static NSString *const bklHealth_mcArticleCellIdentifier = @"bklHealth_mcArticleCellIdentifier";

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initialize];
    }
    return self;
}

- (void)initialize {
    
    _dataSource = [NSArray array];
    
    _tableView = ({
        UITableView *table = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        table.delegate = self;
        table.dataSource = self;
        [table registerClass:[BKLHealth_MCArticleCell class] forCellReuseIdentifier:bklHealth_mcArticleCellIdentifier];
        table.showsVerticalScrollIndicator = NO;
        table.backgroundColor = [UIColor clearColor];
        table;
    });
    [self.contentView addSubview:_tableView];
    
    [self makeConstraints];
}

- (void)makeConstraints {
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
}


#pragma mark - 文章分页 table view delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BKLHealth_MCArticleCell *cell = [tableView dequeueReusableCellWithIdentifier:bklHealth_mcArticleCellIdentifier];
    return cell;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    BKLHealth_MCArticleCell *bklCell = (BKLHealth_MCArticleCell *)cell;
    [bklCell fillData:_dataSource[indexPath.row]];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 110;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.delegate && [self.delegate respondsToSelector:@selector(articlePageView:didSelectedItemAtIndexPath:)]) {
        [self.delegate articlePageView:self didSelectedItemAtIndexPath:indexPath];
    }
}

- (void)fillData:(id)data {
    if (!data) {
        return;
    }
    _dataSource = data;
    [_tableView reloadData];
}

@end

